module test_dist;

import dactor.dist;
import dactor.coroutine;
import dactor.scheduler;
import dactor.actor;
import std.stdio;

void test() {
    while(true) {
        Message m = receive();
        writefln("received: %s, from: %s, to: %s, toName: %s", m.message, m.from, m.to, m.toName);
    }
}

class TestMessage {
    string message;

    this(string msg) {
        message = msg;
    }

    string toString() {
        return message;
    }
}

void test_msg() {
    while(true) {
        {
            Pid pid;
            pid.node = 1;
            send(pid, new TestMessage("hello"));
        }
        sleep(1000);
        {
            send("a@1", new TestMessage("hello"));
        }
        sleep(1000);
    }
}

void main() {
    NodeManager nm = NodeManager.instance;

    Pid pid = spawn(&test);

    assert(nm.registerNode("1", pid));
    assert(nm.findProxy(1) == pid);
    assert(nm.findProxy("1") == pid);

    spawn(&test_msg);

    Scheduler.instance.run();
}

